package aiku.numericalcontroloa.Controller.EmployeeAttendance;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.EmployeeAttendance.ClockinRuleDto;
import aiku.numericalcontroloa.Model.Dto.EmployeeAttendance.HolidaysDto;
import aiku.numericalcontroloa.Service.EmployeeAttendance.ClockinRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author 黄广庭
 * @Date 2024/2/29 17:38
 */
@RestController
@RequestMapping("/clockinRule")
@Slf4j
public class ClockinRuleController {
    private final ClockinRuleService clockinRuleService;

    public ClockinRuleController(ClockinRuleService clockinRuleService) {
        this.clockinRuleService = clockinRuleService;
    }

    /**
     * 获取打卡规则（用于打卡）
     * @param clockinRuleDto
     * @return
     */
    @PostMapping("/getClockinRule")
    public Result getClockinRule(@RequestBody ClockinRuleDto clockinRuleDto){
       return clockinRuleService.getClockinRule(clockinRuleDto);
    }

    /**
     * 获取打卡规则列表
     * @param clockinRuleDto
     * @return
     */
    @PostMapping("/getClockinRuleList")
    public Result getClockinRuleList(@RequestBody ClockinRuleDto clockinRuleDto){
        return clockinRuleService.getClockinRuleList(clockinRuleDto);
    }

    /**
     * 修改打卡规则
     * @param clockinRuleDto
     * @return
     */
    @PostMapping("/updateClockinRule")
    public Result updateClockinRule(@RequestBody ClockinRuleDto clockinRuleDto){
        return clockinRuleService.updateClockinRule(clockinRuleDto);
    }

    /**
     * 重置打卡规则
     * @param clockinRuleDto
     * @return
     */
    @PostMapping("/resetClockinRule")
    public Result resetClockinRule(@RequestBody ClockinRuleDto clockinRuleDto){
        return clockinRuleService.resetClockinRule(clockinRuleDto);
    }

    /**
     * 获取节假日列表
     * @return
     */
    @PostMapping("/getHolidays")
    public Result getHolidays(){
        return clockinRuleService.getHolidays();
    }

    /**
     * 添加节假日
     * @param holidaysDto
     * @return
     */
    @PostMapping("/addHolidays")
    public Result addHolidays(@RequestBody HolidaysDto holidaysDto){
        return clockinRuleService.addHolidays(holidaysDto);
    }

    /**
     * 修改节假日
     * @param holidaysDto
     * @return
     */
    @PostMapping("/updateHolidays")
    public Result updateHolidays(@RequestBody HolidaysDto holidaysDto){
        return clockinRuleService.updateHolidays(holidaysDto);
    }

    /**
     * 删除节假日
     * @param holidaysDto
     * @return
     */
    @PostMapping("/deleteHolidays")
    public Result deleteHolidays(@RequestBody HolidaysDto holidaysDto){
        return clockinRuleService.deleteHolidays(holidaysDto);
    }

    /**
     * 按年获取单个节假日记录
     * @return
     */
    @PostMapping("/getHoliday")
    public Result getHoliday(@RequestBody HolidaysDto holidaysDto){
        return clockinRuleService.getHoliday(holidaysDto);
    }

    /**
     * 今天是否为节假日
     * @return
     */
    @PostMapping("/isHoliday")
    public Result isHoliday(){
        return clockinRuleService.isHoliday();
    }

    /**
     * 获取服务器时间
     * @return
     */
    @PostMapping("/getServerTime")
    public Result getServerTime() {
        // 获取中国标准时间的 ZonedDateTime 对象
        ZonedDateTime chinaTime = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
        // 设置日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 格式化时间
        String formattedChinaTime = chinaTime.format(formatter);
        System.out.println("中国标准时间=====> " + formattedChinaTime);
        return Result.success("获取成功",formattedChinaTime);
    }
}
